/** CODE EVAL [Roman Numeral]
*	Convert cardinal number to Roman numeral
*	I 1
*	V 5
*	X 10
*	L 50
*	C 100
*	D 500
*	M 1000
*/

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>

int readLine(std::string a_line);

int main(int argc, char** argv) {
	std::string line;
	std::ifstream file(argv[1]);
	if(file.is_open()) {
		while(std::getline(file, line)) {
			readLine(line);
//			std::cout << ' ' << line;
			putchar('\n');
		}
	} else {
		printf("File did not open.\n");
	}

	return 0;
}

/**
*	Convert cardinal number to Roman numeral
*	prints Roman numeral
*	@param a_line...current string line
*/
int readLine(std::string a_line) {
	// convert string to int
	int i = atoi(a_line.c_str());

	// check for thousands
	int n = i - 1000;

	// thousandths digit
	int j = i/1000;
	switch(j) {
	case 1:	printf("M");	break;
	case 2:	printf("MM");	break;
	case 3:	printf("MMM");	break;
	default:printf("");	break;
	}
	n = i%1000;
	j = n/100;
	// hundredths digit
	switch(j) {
	case 1:	printf("C");	break;
	case 2:	printf("CC");	break;
	case 3:	printf("CCC");	break;
	case 4:	printf("CD");	break;
	case 5:	printf("D");	break;
	case 6:	printf("DC");	break;
	case 7:	printf("DCC");	break;
	case 8:	printf("DCCC");	break;
	case 9:	printf("CM");	break;
	default:printf("");	break;
	}
	// tens digit
	n = i%100;
	j = n/10;
	switch(j) {
	case 1:	printf("X");	break;
	case 2:	printf("XX");	break;
	case 3:	printf("XXX");	break;
	case 4:	printf("XL");	break;
	case 5:	printf("L");	break;
	case 6:	printf("LX");	break;
	case 7:	printf("LXX");	break;
	case 8:	printf("LXXX");	break;
	case 9:	printf("XC");	break;
	default:printf("");	break;
	}
	// ones digit
	n = i%10;
	j = n/1;
	switch(j) {
	case 1:	printf("I");	break;
	case 2:	printf("II");	break;
	case 3:	printf("III");	break;
	case 4:	printf("IV");	break;
	case 5:	printf("V");	break;
	case 6:	printf("VI");	break;
	case 7:	printf("VII");	break;
	case 8:	printf("VIII");	break;
	case 9:	printf("IX");	break;
	default:printf("");	break;
	}

	return 0;
}